package com.service.creditcard.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.client.model.pojo.creditcard.CreditCard;
import com.client.model.vo.common.Result;
import com.client.model.vo.creditLoanVo.CreditCardVo;
import com.client.model.vo.userVo.ArUserVo;
import com.service.creditcard.service.CreditCardService;
import com.service.creditcard.service.CreditRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author : RulerWood
 * @Data : 2024/4/2 - 19:38
 */
@Slf4j
@RequestMapping("/airui/api/creditcard")
@RestController
@Tag(name = "信用卡接口")
public class CreditCardController {
    @Autowired
    private CreditRecordService creditRecordService;
    @Autowired
    private CreditCardService creditCardService;

    /**
     * 验证用户申请信用卡所提交的信息
     *
     * @param arUserVo 用户信息
     * @param token    用户登录的token
     * @return
     */
    @PostMapping("/verify")
    @Operation(summary = "验证用户输入的信息是否正确")
    public Result verify(@RequestBody ArUserVo arUserVo, @RequestHeader String token) {
        return this.creditRecordService.verify(arUserVo, token);
    }

    /**
     * 我的信用卡信息
     *
     * @param page  第几页
     * @param limit 一叶的条数
     * @return
     */
    @GetMapping("/creditCard")
    @Operation(summary = "我的信用卡分页显示")
    public Result<Page<CreditCard>> getCreditCard(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                  @RequestParam(value = "limit", defaultValue = "3") Integer limit,
                                                  @RequestHeader("token") String token) {
        return this.creditCardService.getCreditCard(page, limit,token);
    }

    /**
     * 还款
     * @param creditCardVo 与取现一致的vo类
     * @return
     */
    @PostMapping("/reBackMoney")
    @Operation(summary = "还款接口")
    public Result reBackMoney(@RequestBody CreditCardVo creditCardVo) {
        return this.creditCardService.rebackMoney(creditCardVo);
    }

    /**
     * 取现
     * @param creditCardVo 与还款一致的vo类
     * @return
     */
    @PostMapping("/borrowMoney")
    @Operation(summary = "取现接口")
    public Result borrowMoney(@RequestBody CreditCardVo creditCardVo) {
        return this.creditCardService.borrowMoney(creditCardVo);
    }

    /**
     * 用户查看自己的信用卡审核进度
     * @param token 通过token去查找当前用户的信息进而去检索审核记录表
     * @return
     */
    @GetMapping("/myExamine")
    @Operation(summary = "查看我的信用卡审核进度")
    public Result myExamine(@RequestHeader("token") String token) {
        return this.creditRecordService.myExamine(token);
    }

    /**
     * 根据用户输入的银行卡号，去找寻该张银行卡是否存在
     * @param cardNum 银行卡号
     * @return
     */
    @GetMapping("/findBankCardByCardNum")
    public Result getBankCardByCardNum(String cardNum) {
        return this.creditCardService.getBankCardByCardNum(cardNum);
    }

}
